var BULLET_BUFFER=[];
var Bullet = cc.Sprite.extend({
    _power : 0,
    _speed : 0,
    _xSpdScale : 1,
    _ySpdScale : 1,
    ///////////////////////////////////////////////////////////
    ctor : function(filename,power,speed){
        this._super(filename);
        this._power = power;
        this._speed = speed;
        //this._visible = false;
    },
    onEnter:function () {
        this._super();
    },
    onExit : function(){
        this._super();
    },
    ////////////////////////// moving //////////////////////////
    getPower : function(){
        return this._power;
    },
    angle : function( targetPos ) {
        var fenZi =  targetPos.y - this.bornPos.y;
        var fenMu =  targetPos.x - this.bornPos.x;
        var angle = Math.atan( fenZi/fenMu );
        return -angle*180*0.318310;
    },
    // you must set this position first
    setSpeedScale : function(targetPos,distance){
        var xScale = ( targetPos.x - this.getPositionX() )/distance;
        var yScale = ( this.getPositionY() - targetPos.y )/distance;
        this._xSpdScale =  xScale;
        this._ySpdScale =  yScale;
        this.runAction( cc.RepeatForever.create(
            cc.RotateBy.create( 1,-360 )
        ) );
    },
    moving : function(dt){
        if ( this.isVisible() ){
            var x = this.x, y = this.y;
            var rota = this.getRotation();
            this.x = x + this._speed * this._xSpdScale * dt;
            this.y = y - this._speed * this._ySpdScale * dt;

            if ( x < 0|| x > cc.director.getWinSize().width ||
                y < 0 || y > cc.director.getWinSize().height ) {
                this.setVisible(false);
                this.stopAllActions();
            }
        }
    },
    collideRect:function (x, y) {
        var width=height=30;
        return cc.rect(x-width*0.5, y-height*0.5, width, height);
    }
});
////////////////////////////////////////////////////////////////
Bullet.create = function (filename,power,speed ) {
    var bullet = new Bullet(filename,power,speed );
    //put  into our container
    BULLET_BUFFER.push( bullet );
    return bullet;
};

